package com.gaokao.demo.controller;


import cn.hutool.core.convert.Convert;
import cn.hutool.json.JSONUtil;
import com.gaokao.demo.entity.Onescoreonefile;
import com.gaokao.demo.entity.ProfessionalScore;
import com.gaokao.demo.service.IOnescoreonefileService;
import com.gaokao.demo.vo.ResultResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author szs
 */
@RestController
@RequestMapping("/onescoreonefile")
public class OnescoreonefileController {

    @Autowired
    private IOnescoreonefileService onescoreonefileService;

    @RequestMapping("/getList")
    public String getList() {
        return "";
    }

    /**
     * 近两年的分数和位次
     *
     * @param stuLeibie  文理科
     * @param stuAddress 地区
     * @param stuScores  分数
     * @param dates      今年
     * @return
     */
    @RequestMapping("/getPastScore")
    public String getPastScore(String stuLeibie, String stuAddress, Double stuScores, Integer dates) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("stuScores", stuScores);
        map.put("dates", dates);
        map.put("stuLeibie", stuLeibie);
        map.put("stuAddress", stuAddress);
        ArrayList<Map<String, Object>> list = new ArrayList<>();
        for (int i = 0; i < 2; i++) {
            HashMap<String, Object> hashMap = new HashMap<>();
            map.put("year", dates - 1 - i);
            Onescoreonefile pastScore = this.onescoreonefileService.getPastScore(map);
            hashMap.put("year", dates - 1 - i);
            hashMap.put("stuLeibie", pastScore.getStuLeibie());
            hashMap.put("qujian", pastScore.getStuSumNumbers() + "~" + (Convert.toInt(pastScore.getStuSumNumbers()) + Convert.toInt(pastScore.getStuNumber())));
            hashMap.put("stuScores", pastScore.getStuScores());
            list.add(hashMap);
        }
        ResultResponse resultResponse = null;
        resultResponse = ResultResponse.newSuccess("success", list);
        return JSONUtil.toJsonStr(resultResponse);
    }

    /**
     * 指定年份可以报考的学校
     *
     * @param stuScores 对应的分数
     * @param dates     指定年份
     * @return
     */
    @RequestMapping("/getSchool")
    public String getSchool(Double stuScores, Integer dates) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("score", stuScores);
        map.put("dates", dates);
        List<ProfessionalScore> list = this.onescoreonefileService.getSchool(map);
        ResultResponse resultResponse = null;
        resultResponse = ResultResponse.newSuccess("success", list);
        return JSONUtil.toJsonStr(resultResponse);
    }

}
